<?php

namespace Module\PageNotice\Core;

use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use ModStart\Admin\Config\AdminMenu;
use ModStart\Core\Hook\ModStartHook;

class ModuleServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(Dispatcher $events)
    {
        AdminMenu::register(function () {
            return [
                [
                    'title' => '功能设置',
                    'icon' => 'tools',
                    'sort' => 300,
                    'children' => [
                        [
                            'title' => '系统全局通知',
                            'url' => '\Module\PageNotice\Admin\Controller\ConfigController@index',
                        ],
                    ]
                ],
            ];
        });
        ModStartHook::subscribe('PageBodyAppend', function () {
            $startTime = modstart_config('PageNotice_Start', '');
            $endTime = modstart_config('PageNotice_End', '');
            $show = true;
            if ($startTime && strtotime($startTime) > time()) {
                $show = false;
            } else if ($endTime && strtotime($endTime) < time()) {
                $show = false;
            }
            if (!$show) {
                return '';
            }
            return View::make('module::PageNotice.View.script')->render();
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

    }
}
